package com.fr.chart;

import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.chart.base.equals.Equals;
import com.fr.chart.core.glyph.ChartGlyph;
import com.fr.chart.core.glyph.LegendGlyph;
import com.fr.chart.core.glyph.PlotGlyph;
import com.fr.chart.legend.Legend;
import com.fr.chart.plot.CustomPlot;
import com.fr.chart.plot.MeterPlot;
import com.fr.chart.plot.Plot;
import com.fr.chart.plot.RangePlot;
import com.fr.chart.plot.SeriesCollection;
import com.fr.data.ChartData;
import com.fr.report.io.xml.ReportXMLUtils;
import com.fr.report.js.NameJavaScriptGroup;
import java.util.Map;

public class Chart extends ChartModule
{
  private static final long serialVersionUID = -2818043793300636874L;
  public static final String XML_TAG = "Chart";
  private Title title;
  private Plot plot;
  private boolean isJSDraw;

  public Chart()
  {
    this(null);
  }

  public Chart(Plot paramPlot)
  {
    this.isJSDraw = true;
    this.plot = paramPlot;
  }

  public Title getTitle()
  {
    return this.title;
  }

  public void setTitle(Title paramTitle)
  {
    this.title = paramTitle;
  }

  public Plot getPlot()
  {
    return this.plot;
  }

  public void setPlot(Plot paramPlot)
  {
    this.plot = paramPlot;
  }

  public void setJSDraw(boolean paramBoolean)
  {
    this.isJSDraw = paramBoolean;
  }

  public boolean isJSDraw()
  {
    return this.isJSDraw;
  }

  public ChartGlyph createGlyph(ChartData paramChartData)
  {
    ChartGlyph localChartGlyph = new ChartGlyph();
    localChartGlyph.setInfo(getInfo());
    localChartGlyph.setJSDraw(isJSDraw());
    if (this.title != null)
      localChartGlyph.setTitleGlyph(this.title.createGlyph());
    PlotGlyph localPlotGlyph = this.plot.createPlotGlyph(paramChartData);
    localChartGlyph.setPlotGlyph(localPlotGlyph);
    LegendGlyph localLegendGlyph = this.plot.createLegendGlyph(localPlotGlyph);
    localChartGlyph.setLegendGlyph(localLegendGlyph);
    return localChartGlyph;
  }

  public void switchPlot(Plot paramPlot)
  {
    Plot localPlot = getPlot();
    if (localPlot != null)
    {
      if ((paramPlot instanceof RangePlot) || (paramPlot instanceof MeterPlot))
        paramPlot.setLegend(null);
      else if ((localPlot instanceof RangePlot) || (localPlot instanceof MeterPlot))
        paramPlot.setLegend(new Legend());
      else
        paramPlot.setLegend(localPlot.getLegend());
      paramPlot.setInfo(localPlot.getInfo());
      paramPlot.getSeriesCollection().getSeriesAttrMap().clear();
      if (paramPlot instanceof CustomPlot)
        ChartFactory.createSeriesMap4CustomPlot(paramPlot);
    }
    setPlot(paramPlot);
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    super.readXML(paramXMLableReader);
    if (paramXMLableReader.isChildNode())
    {
      String str1 = paramXMLableReader.getTagName();
      if (str1.equals("Title"))
      {
        this.title = new Title();
        paramXMLableReader.readXMLObject(this.title);
      }
      else if (str1.equals("Plot"))
      {
        this.plot = ((Plot)ReportXMLUtils.readXMLable(paramXMLableReader));
      }
      else if (("NameJavaScriptGroup".equals(str1)) || ("NameHyperlinks".equals(str1)) || ("HyperlinkMap".equals(str1)))
      {
        this.plot.setHotHyperLink((NameJavaScriptGroup)paramXMLableReader.readXMLObject(new NameJavaScriptGroup()));
      }
      else if (str1.equals("ChartAttr"))
      {
        String str2;
        if ((str2 = paramXMLableReader.getAttr("isJSDraw")) != null)
          setJSDraw(Boolean.valueOf(str2).booleanValue());
      }
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("Chart").attr("class", getClass().getName());
    super.writeXML(paramXMLPrintWriter);
    paramXMLPrintWriter.startTAG("ChartAttr").attr("isJSDraw", this.isJSDraw).end();
    if (this.title != null)
      this.title.writeXML(paramXMLPrintWriter);
    if (this.plot != null)
      ReportXMLUtils.writeXMLable(paramXMLPrintWriter, this.plot, "Plot");
    paramXMLPrintWriter.end();
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    Chart localChart = (Chart)super.clone();
    if (this.title != null)
      localChart.title = ((Title)this.title.clone());
    if (this.plot != null)
      localChart.plot = ((Plot)this.plot.clone());
    return localChart;
  }

  public boolean equals(Object paramObject)
  {
    if (!(paramObject instanceof Chart))
      return false;
    Chart localChart = (Chart)paramObject;
    if (!(super.equals(localChart)))
      return false;
    if (!(Equals.equals(localChart.getPlot(), getPlot())))
      return false;
    if (!(Equals.equals(localChart.getTitle(), getTitle())))
      return false;
    return (localChart.isJSDraw == this.isJSDraw);
  }
}